import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import { router } from 'dva';
import moment from "moment";
const { Link } = router;

export default (self, categoryList) => [
  {
    title: 'ID',
    name: 'id',
    formItem: {type: 'hidden'}
  },{
    title: '名称',
    name: 'name',
    searchItem: {group: 'abc'},
    tableItem: {},
    formItem: {rules:[]},
  },
  ,{
    title: '总分',
    name: 'sumScore',
    tableItem: {},
    // formItem: {
    //   type: 'number'
    // },
  },{
    title: '类别',
    name: 'categoryId',
    dict: categoryList.map(item=> {return {code: item.id, codeName: item.name}}),
    tableItem: {},
    formItem: {type: 'select',rules: []}
  },
  {
    title: '及格分',
    name: 'passScore',
    tableItem: {},
    formItem: {
      type: 'number',
    },
  },{
    title: '描述',
    name: 'description',
    formItem: {type: 'textarea'}
  },{
    title: '状态',
    name: 'publishStatus',
    dict: [{code: 'PUBLISHED', codeName: '已发布'}, {code: 'UN_PUBLISHED', codeName: '未发布'}],
    tableItem: {},
  },
  {
    title: '创建时间',
    name: 'ceateTime',
    tableItem: {
      render: text =>
      moment.utc(text).format('YYYY-MM-DD HH:mm')},
  },
  {
    title: '更新时间',
    name: 'updateTime',
    tableItem: {
      render: text =>
        moment.utc(text).format('YYYY-MM-DD HH:mm')},
  },
  {
    title: '操作',
    tableItem: {
      width: 180,
      render: (text, record) => {
        let publishBtn = '';
        if (record.publishStatus == 'UN_PUBLISHED') {
          publishBtn = <Button tooltip="发布" onClick={e => self.onPublish(record)}>
            <Icon type="CheckCircleOutlined" antd/>
          </Button>
        }
        return <DataTable.Oper>
          <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
            <Icon type="edit"/>
          </Button>
          <Button tooltip="删除" onClick={e => self.onDelete(record)}>
            <Icon type="trash"/>
          </Button>
          {publishBtn}
          <Button tooltip="详情">
            <Link to={"/exams/detail?id=" + record.id}>
              <Icon type="info" />
            </Link>
          </Button>
        </DataTable.Oper>
      }
    }
  }
];

export const createFormCloumns = (self, categoryList)=>[
  {
    title: '试卷名称',
    name: 'examPaperName',
    formItem: {rules:[]},
  },{
    title: '类别',
    name: 'categoryId',
    dict: categoryList.map(item=> {return {code: item.id, codeName: item.name}}),
    formItem: {type: 'select',rules: []}
  },{
    title: '试题文件',
    name: 'tmpl',
    formItem: {
      type: 'upload',
      fileTypes: ['.xls', '.xlsx'],
      listType: 'text',
      max: 1,
      rules: [
        {
          required: true,
          message: '请上传文件'
        }
      ]
    }},{
    title: '及格分',
    name: 'passScore',
    tableItem: {},
    formItem: {
      type: 'number',
    },
  },{
    title: '描述',
    name: 'description',
    formItem: {type: 'textarea'}
  },];